<include file="Public:header" />
<script src="__PUBLIC__/js/chart/highcharts.js"></script>
<script src="__PUBLIC__/js/chart/modules/exporting.js"></script>
<script src="__PUBLIC__/js/chart/modules/funnel.js"></script>
<script src="__PUBLIC__/style/js/plugins/nice-scroll/jquery.nicescroll.min.js" type="text/javascript"></script>
<script type="text/javascript" src="__PUBLIC__/style/js/TableFreeze.js"></script>

<!-- echarts -->
<script type="text/javascript" src="__PUBLIC__/js/echarts/echarts.js"></script>
<!-- daterangepicker -->
<link href="__PUBLIC__/css/daterangepicker.css" rel="stylesheet">
<script src="__PUBLIC__/js/daterangepicker/daterangepicker.js"></script>
<!--jQuery导出插件-->
<script type="text/javascript" src="__PUBLIC__/js/table-export/jquery.base64.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/table-export/tableExport.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/table-export/jspdf/libs/sprintf.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/table-export/jspdf/jspdf.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/table-export/jspdf/libs/base64.js"></script>
<!--jQuery导出插件-->
<style>
    body{
        overflow-y: hidden;
    }
</style>

<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <include file="Public:analytics_left" />
                <input type="hidden" id="content_id" value="{$content_id}">
                <div class="col-lg-10">
                    <div class="ibox-content" style="padding-bottom:10px;border-bottom: none;">
                        <include file="Public:alert" />
                        <form id="" class="form-group" method="get" style="margin-bottom: 0px;">
                            <input type="hidden" name="m" value="dataAnalysis" />
                            <input type="hidden" name="a" value="ispresent" />
                            <div class="row" style="height: 45px;">
                                <div class="col-lg-4">
                                    <div class="pull-left" >
										<span style="font-size: 18px;color: #000;">
											到场数自定义分析
										</span>
                                    </div>
                                </div>
                                <div class="col-lg-5">
                                </div>
                                <div class="col-lg-3">
                                    
                                </div>
                            </div>

                            <input type="hidden" name="dbname" id="dbname" value="{$dbname}" />
                            <input type="hidden" name="select_type" value="{$select_type}" />
                            <input type="hidden" name="content_id" value="{$_GET['content_id']}" />
                            <div class="row">
                                <div class="col-lg-12" >
                                    <div class="nav pull-left" style="margin:2px 0 0 15px;width: 165px;margin-right: 20px;">
                                        <div class="input-group">
                                            <select class="form-control input-sm " style="min-width:165px;max-width: 165px;" name="field" >
                                                <option value="industry" <if condition = "$_GET['field'] eq 'industry'"> selected</if>>行业</option>
                                                <option value="location" <if condition = "$_GET['field'] eq 'location'"> selected</if> >城市</option>

                                            </select>
                                            <!--<select class="form-control select2" style="min-width:165px;max-width: 165px;height: 0px;">-->
                                            <!--<option class="all" value="项目类型">回款项目类型</option>-->
                                            <!--<option class="all" value="所属行业">所属行业</option>-->
                                            <!--<option class="all" value="所属地区">所属地区</option>-->
                                            <!--</select>-->
                                        </div>
                                    </div>
                                    <div class="nav pull-left" style="margin:2px 0 0 0;">
                                        <div class="input-group">
                                            <input type="text" name="between_date" id="reservation" class="form-control" style="width:300px;"/>
                                            <i class="glyphicon glyphicon-calendar fa fa-calendar" style="position: absolute;bottom: 10px;right: 24px;top: auto;cursor: pointer;"></i>
                                        </div>
                                    </div>
                                    <if condition = "$_GET['dbname'] eq ''">
                                        <div class="nav pull-left" style="margin:2px 0 0 15px;width: 165px;">
                                            <div class="input-group">
                                                <select class="form-control select2" style="min-width:165px;max-width: 165px;height: 0px;" name="department" id="department" onchange="changeRole()">
                                                    <option class="all" value="all">{:L('ALL')}</option>
                                                    <volist name="departmentList" id="vo">
                                                        <option value="{$vo.department_id}" <if condition="$_GET['department'] eq $vo['department_id']">selected</if>>{$vo.name}</option>
                                                    </volist>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="nav pull-left" style="margin:2px 0 0 15px;width: 165px;">
                                            <div class="input-group">
                                                <select class="form-control select2" style="min-width:165px;max-width: 165px;height: 0px;" name="role" id="role" onchange="changeCondition()">
                                                    <option class="all" value="all">{:L('ALL')}</option>
                                                    <volist name="roleList" id="vo">
                                                        <option value="{$vo.role_id}" <if condition="$_GET['role'] eq $vo['role_id']">selected</if>>{$vo.role_name}-{$vo.user_name}</option>
                                                    </volist>
                                                </select>
                                            </div>
                                        </div>
                                    </if>



                                    <div class="pull-left" style="margin-left: 20px;">
                                        <button type="submit" id="analytics_search" class="btn btn-primary">立即搜索</button>
                                    </div>
                                </div>
                            </div>


                        </form>
                    </div>
                    <div class="ibox-content clearfix" id="right_height" style="border-top: none;">
                        <div id="content_8" class="th_content full-height-scroll">
                            <div id="canvas_pro" style="max-width:50%;min-width:50%; height: 450px;" class="col-lg-6">
                                <div style="background-color:#fff;"><include file="Public:nodata" /></div>
                            </div>
                            <div class="col-lg-5" style="margin-left: 5px;">
                                <div class="slimScrollDiv" style="position: relative; overflow: hidden; width: auto; height: 100%;"><div class="full-height-scroll" style="left: 0px; top: 0px; overflow: hidden; width: auto; height: 100%;">
                                    <table class="table table-hover " style="margin-top: 80px;border:1px solid #ccc;background-color: #f9f9f9;">
                                        <tr style="background-color: #F4F4F4;">
                                            <td style="border-top: none;">名称</td>
                                            <td style="border-top: none;">个数</td>
                                            <td style="border-top: none;">占比</td>
                                        </tr>
                                        <volist name="field_count_list" id="vo">
                                            <tr>
                                                <td>{$vo['name']}</td>
                                                <td>{$vo['num']}</td>
                                                <td>{$vo['rate']}%</td>
                                            </tr>
                                        </volist>
                                    </table>
                                </div><div class="slimScrollBar" style="background: rgb(153, 153, 153); width: 7px; position: absolute; top: 0px; opacity: 0.4; display: none; border-radius: 7px; z-index: 99; right: 1px; height: 291px;"></div><div class="slimScrollRail" style="width: 7px; height: 100%; position: absolute; top: 0px; display: none; border-radius: 7px; background: rgb(51, 51, 51); opacity: 0.2; z-index: 90; right: 1px;"></div></div>
                            </div>
                        </div>



                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="hide" id="dialog-import" title="{:L('IMPORT_DATA')}">
    <div class="spiner-example">
        <div class="sk-spinner sk-spinner-three-bounce">
            <div class="sk-bounce1"></div>
            <div class="sk-bounce2"></div>
            <div class="sk-bounce3"></div>
        </div>
    </div>
</div>
<div style="display: none;" id="dialog-role-info" title="员工信息">
    <div class="spiner-example">
        <div class="sk-spinner sk-spinner-three-bounce">
            <div class="sk-bounce1"></div>
            <div class="sk-bounce2"></div>
            <div class="sk-bounce3"></div>
        </div>
    </div>
</div>
<div style="display:none" id="dialog-addduibi" title="添加对比">
    <div class="spiner-example">
        <div class="sk-spinner sk-spinner-three-bounce">
            <div class="sk-bounce1"></div>
            <div class="sk-bounce2"></div>
            <div class="sk-bounce3"></div>
        </div>
    </div>
</div>
<script type="text/javascript">
    //时间插件
    $('#reservation').daterangepicker({
        startDate: '{$start_date}',
        endDate: '{$end_date}',
        //minDate: '01/01/2012',    //最小时间
        maxDate : moment(), //最大时间
        showDropdowns : true,
        showWeekNumbers : false, //是否显示第几周
        // timePicker : true, //是否显示小时和分钟
        // timePickerIncrement : 60, //时间的增量，单位为分钟
        timePicker12Hour : false, //是否使用12小时制来显示时间
        ranges : {
            //'最近1小时': [moment().subtract('hours',1), moment()],
            '今日': [moment().startOf('day'), moment()],
            '昨日': [moment().subtract('days', 1).startOf('day'), moment().subtract('days', 1).endOf('day')],
            '上月': [moment().subtract('days', '{$daterange[0][start_day]}'), moment().subtract('days', '{$daterange[0][end_day]}')],
            '本月': [moment().subtract('days', '{$daterange[1][start_day]}'), moment()],
            '上季度': [moment().subtract('days', '{$daterange[2][start_day]}'), moment().subtract('days', '{$daterange[2][end_day]}')],
            '本季度': [moment().subtract('days', '{$daterange[3][start_day]}'), moment()],
            '上一年': [moment().subtract('days', '{$daterange[4][start_day]}'), moment().subtract('days', '{$daterange[4][end_day]}')],
            '本年': [moment().subtract('days', '{$daterange[5][start_day]}'), moment()],
            // '最近7日': [moment().subtract('days', 6), moment()],
            // '最近30日': [moment().subtract('days', 29), moment()]
        },
        opens : 'right', //日期选择框的弹出位置
        buttonClasses : [ 'btn btn-default' ],
        applyClass : 'btn-small btn-primary blue',
        cancelClass : 'btn-small',
        separator : ' to ',
        locale : {
            applyLabel : '确定',
            cancelLabel : '取消',
            fromLabel : '起始时间',
            toLabel : '结束时间',
            customRangeLabel : '自定义',
            daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
            monthNames: ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],
            firstDay : 1 ,
            format : 'YYYY-MM-DD', //控件中from和to 显示的日期格式
        },
        "alwaysShowCalendars": true,
        function(start, end, label) {
            //回调
            $('#reservation').val(start.format('YYYY-MM-DD HH:mm:ss') + ' - ' + end.format('YYYY-MM-DD HH:mm:ss'))
            // console.log("New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')");
        }
    });

    $("#dialog-addduibi").dialog({
        autoOpen: false,
        modal: true,
        width: 600,
        maxHeight: 450,
        position: ["center",100],
        buttons: {
            "确定": function () {
                var select_role = 0;
                var arys = new Array();
                var type_id = $('#type_id').val();
                var content_id = $('#content_id').val();
                $('#types_id').val(type_id);
                $('#contents_id').val(content_id);
                $('.duibi_role_id').each(function(k, v){
                    duibi_id = $(this).find("option:selected").val();
                    if(duibi_id){
                        if(jQuery.inArray(duibi_id,arys) >= 0){
                            swal({
                                title: "对比员工不能重复！",
                                type: "error"
                            });
                            return false;
                        }
                        arys[k] = duibi_id;
                        select_role +=1;
                    }
                })
                var select_type = $('#select_type').val();
                if(select_role < 2){
                    swal({
                        title: "对比员工至少2位!",
                        type: "error"
                    });
                    return false;
                }else if(select_type == '' || select_type == 0){
                    swal({
                        title: "对比时间不能为空！",
                        type: "error"
                    });
                    return false;
                }else{
                    $('#remind_form').submit();
                    return true;
                }
            },
            "取消": function () {
                $(this).dialog("close");
            }
        }
    });

    $("#addduibi").click(function(){
        var mokuai_id = $('#type_id').val();
        var content_id = $('#content_id').val();
        var dbname = $('#dbname').val();
        var select_type = $('#select_type').val();
        $('#dialog-addduibi').dialog('open');
        $('#dialog-addduibi').load('{:U("business/addduibi","content_id=")}'+content_id +'&dbname='+dbname+'&select_type='+select_type);
    });

    $("#dialog-role-info").dialog({
        autoOpen: false,
        modal: true,
        width: 600,
        maxHeight: 550,
        position: ["center",100]
    });

    $(".role_info").click(function(){
        $role_id = $(this).attr('rel');
        $('#dialog-role-info').dialog('open');
        $('#dialog-role-info').load('{:U("user/dialoginfo","id=")}'+$role_id);
    });
    $(function () {
        var canvas_width = $('#an_chart').width();
        var canvas_height = $('#an_chart').height();
        $('#canvas_pro').css({width:canvas_width*0.6});

        var chart1; //客戶信息來源饼状图
        $('#canvas_pro').highcharts({
            chart1: {
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false
            },
            // title: {
            // 	text: '{:L('CUSTOMER_SOURCE_STATISTICS_SUM_TO',array($field['origin'],$total_report['own_customer_count']))}'
            // },
            title :{
                text : ''
            },
            tooltip: {
                pointFormat: '{series.name}: <b>{point.percentage:.2f}%</b>',
                percentageDecimals: 1
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: true,
                        format: '<b>{point.name}</b>: {point.percentage:.2f} %',
                        style: {
                            color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                        }
                    },
                    showInLegend: true
                }
            },
            series: [{
                type: 'pie',
                name: '{$field_name}',
                data: [
                    {$field_count}
                ]
            }]
        });

        //var chart2; 客戶信息來源柱状图
        $('#canvas_pro_zhu').highcharts({
            chart: {
                type: 'column'
            },
            title: {
                text: ''
            },
            subtitle: {
                text: ''
            },
            xAxis: {
                type: 'category',
                labels: {
                    rotation: -45,
                    style: {
                        fontSize: '13px',
                        fontFamily: 'Verdana, sans-serif'
                    }
                }
            },
            yAxis: {
                min: 0,
                title: {
                    text: '数量 (个)'
                }
            },
            legend: {
                enabled: false
            },
            tooltip: {
                pointFormat: '客户总数: <b>{point.y:.1f} 个</b>'
            },
            series: [{
                name: '总客户数',
                data: [
                    {$field_count}
                ],
                dataLabels: {
                    enabled: true,
                    rotation: -90,
                    color: '#FFFFFF',
                    align: 'right',
                    format: '{point.y:.1f}', // one decimal
                    y: 10, // 10 pixels down from the top
                    style: {
                        fontSize: '13px',
                        fontFamily: 'Verdana, sans-serif'
                    }
                }
            }]
        });
    });


    // 搜索
    $(".select_time_a").click(function(){
        var select_time = $(this).attr('rel');
        var type_id = "{$_GET['type_id']}";
        var content_id = "{$_GET['content_id']}";
        window.location.href="{:U('business/analytics','&type_id=')}"+type_id+'&content_id='+content_id+'&select_type='+select_time+'&department=all&role=all';
    });

    $("#user_type").click(function(){
        var user_type = $(this).is(':checked');
        var between_date = $('#reservation').val();
        if(user_type == true){
            window.location.href = "{:U('business/analytics','content_id=1'.'&between_date=')}"+between_date;
        }else{
            window.location.href = "{:U('business/analytics','&content_id=1'.'&between_date=')}"+between_date+'&user_type=1';
        }
    });
</script>
<include file="Public:footer" />
